package view.pane;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import controller.GameSettings;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;

import view.Gui;

@SuppressWarnings("serial")
public class ConfigurationPane extends JPanel {
	Gui gui;
	public ConfigurationPane(Gui guiParam) {
                LayoutManager l = new BoxLayout(this, WIDTH);
                //setLayout(l);
                this.gui = guiParam;

                JPanel panel = new JPanel(new GridLayout(2,3));
                
		JButton gameButton = new JButton("Start Game");
                gameButton.setSize(500, 10);
		
		final JCheckBox usePasswords = new JCheckBox("Use passwords");
                final JLabel numberPlayersLabel = new JLabel("Number of players");
		final JTextField numberPlayers = new JTextField("10", 10);
                numberPlayers.setSize(20, 10);
		final GameSettings settings = new GameSettings();
		
		gameButton.addActionListener( 
			new ActionListener() {
                                @Override
				public void actionPerformed(ActionEvent e) {
					int nrPlayers = Integer.parseInt(numberPlayers.getText());
					settings.numberPlayers = nrPlayers;
					
					settings.usePasswords = usePasswords.isSelected();
					gui.setSettings(settings);
					gui.updatePane(new EnlistmentPane(gui));
				}
			}
		);

                panel.add(numberPlayersLabel);
                panel.add(new Component(){});
                panel.add(new Component(){});

                panel.add(numberPlayers);
		panel.add(usePasswords);
		panel.add(gameButton);
                this.add(panel);
	}

}
